pub mod animate;
pub mod class;
pub mod custom_widget;
pub mod loader;
pub mod map_editor;
pub mod menu;
pub mod ron;
pub mod ui;
pub mod ui_class;
pub mod widget;
pub mod collider;

use animate::AnimatorPlugin;
use bevy::prelude::*;
use loader::LoadPlugin;
use map_editor::MapEditorPlugin;
use menu::MenuPlugin;
use serde::{Deserialize, Serialize};
use ui::game_map::GameMapSettings;
use crate::collider::ColiderPlugin;
use crate::ui::ui_play::PlayGamePlugin;

#[derive(Default, States, Debug, Hash, PartialEq, Eq, Clone)]
pub enum GameState {
    #[default]
    Loading,
    LoadMap,
    Menu,
    GameEnter,
    Gaming,
    MapEditor,
}

pub struct GamePlugin;

impl Plugin for GamePlugin {
    fn build(&self, app: &mut App) {
        app.init_state::<GameState>()
            .insert_resource(GameMapSettings::default())
            .add_plugins((
                DefaultPlugins.set(WindowPlugin {
                    primary_window: Some(Window {
                        title: "Tank War".to_string(),
                        resolution: (1080., 720.).into(),
                        ..default()
                    }),
                    ..default()
                }),
                LoadPlugin,
                MenuPlugin,
                AnimatorPlugin,
                MapEditorPlugin,
                PlayGamePlugin,
                ColiderPlugin
            ));
    }
}

#[derive(Component)]
pub struct OnExitClean;

#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct GameLevel {
    pub map: Vec<Vec<usize>>,
    pub name: String,
}

impl Default for GameLevel {
    fn default() -> Self {
        Self {
            map: vec![vec![0; 26]; 26],
            name: String::new(),
        }
    }
}

#[derive(Clone, Asset, Serialize, Deserialize, TypePath, Resource, Default, Debug)]
pub struct GameMaps {
    pub maps: Vec<GameLevel>,
}
